using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAL;
using Utility;
namespace BUS
{
    public class KHACHHANG_BUS
    {
        public static void insert(KhachHang_DTO kh)
        {
           KHACHHANG_DAL khdal = new KHACHHANG_DAL();
           khdal.insert(kh);
        }
        public static void update(KhachHang_DTO kh)
        {
            KHACHHANG_DAL khdal = new KHACHHANG_DAL();
            khdal.update(kh);
        }
        public static void delete(int makh)
        {
            KHACHHANG_DAL khdal = new KHACHHANG_DAL();
            khdal.delete(makh);
        }
        public static tbKhachHangCollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            KHACHHANG_DAL khdal = new KHACHHANG_DAL();
            return khdal.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbKhachHangCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            KHACHHANG_DAL khdal = new KHACHHANG_DAL();
            return khdal.Get(cri.Criter, 0, 0, tbKhachHangColums.MAKH.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static KhachHang_DTO GetByID(int iD)
        {   int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbKhachHangColums.MAKH.ToString(), Condition.EQUAL, iD);
           KHACHHANG_DAL khdal = new KHACHHANG_DAL();
            tbKhachHangCollection KHcltion = khdal.Get(cri.Criter, 0, 0, tbKhachHangColums.MAKH.ToString(), OrderDirection.ASC.ToString(), out total);
            if (KHcltion.Count > 0)
                return KHcltion[0];
            return null;

        }
        public static KhachHang_DTO GetByEmail(string email)
        {
            int total = 0;


            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbKhachHangColums.EMAIL.ToString(), Condition.EQUAL, email);
            KHACHHANG_DAL khdal = new KHACHHANG_DAL();
            tbKhachHangCollection KHcltion = khdal.Get(cri.Criter, 0, 0, tbKhachHangColums.MAKH.ToString(), OrderDirection.ASC.ToString(), out total);
            if (KHcltion.Count > 0)
                return KHcltion[0];
            return null;

        }
    }
}
